package com.example.qxfw.rcyw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.qxfw.common.entity.ny.DiseaseMonitorInfo;
import com.example.qxfw.rcyw.mapper.DiseaseMonitorInfoMapper;
import com.example.qxfw.rcyw.service.DiseaseMonitorInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service
public class DiseaseMonitorInfoServiceImpl implements DiseaseMonitorInfoService {
    @Autowired
    private DiseaseMonitorInfoMapper diseaseMonitorInfoMapper;

    @Override
    public List<DiseaseMonitorInfo> getMonitorDisease(Integer argDiseasAutoHour) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - argDiseasAutoHour);
        Timestamp warningtime = Timestamp.valueOf(sdf.format(calendar.getTime()));
        LambdaQueryWrapper<DiseaseMonitorInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(DiseaseMonitorInfo::getWarningtime,warningtime).eq(DiseaseMonitorInfo::getIsremove,0).orderByDesc(DiseaseMonitorInfo::getWarningtime);
        List<DiseaseMonitorInfo> diseaseMonitorInfos = diseaseMonitorInfoMapper.selectList(queryWrapper);
        return diseaseMonitorInfos;
    }

    @Override
    public Integer updateMonitorDisease(DiseaseMonitorInfo diseaseMonitorInfo) {
        return diseaseMonitorInfoMapper.updateById(diseaseMonitorInfo);
    }
}
